<?php

namespace app\admin\controller;

use think\Log;
use think\Db;
use fast\Http;
use app\common\controller\Backend;


/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {	
        $hooks = config('addons.hooks');

        $countuser  = $this->selectcount($this->GameDBConfig,'user');  //总注册人数
        
        $totaluser  = $this->selectcount($this->GameDBConfig,'user',"FROM_UNIXTIME(createTime/1000,'%Y-%m') = date_format(now(),'%Y-%m')");  //当月注册人数
        $totalviews = Db::table('fa_v_annal_room')->field('roomid')->where("roomcode > 0 and FROM_UNIXTIME(endtime/1000,'%Y-%m') = date_format(now(),'%Y-%m')")->group('roomid,createtime')->count();//当月开房数(大厅+俱乐部)
        $totalorder = Db::name('v_annal_room')->where("FROM_UNIXTIME(endtime/1000,'%Y-%m') = date_format(now(),'%Y-%m')")->sum('roomcode'); //当月消耗房卡(大厅+俱乐部)
        $totalorderamount = Db::name('y_onlineorder')->where(['status'=>2])->where("FROM_UNIXTIME(addtime/1000,'%Y-%m') = date_format(now(),'%Y-%m')")->sum('orderamount');//当月充值金额(客户端+代理)
        $totalagency = Db::name('y_agency')->where(['AgeType'=>1])->where("DATE_FORMAT(RegisterTime,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')")->count();//当月新增代理
        $totalincome = Db::name('y_promotionincome')->where("FROM_UNIXTIME(addtime/1000,'%Y-%m') = date_format(now(),'%Y-%m')")->sum('money');//当月代理积累提成(代理支付提成+客户端支付提成)
        
        $todayusersignup = $this->selectcount($this->GameDBConfig,'user',"FROM_UNIXTIME(createTime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')");//今日注册数
        $todayuserlogin = $this->selectcount($this->GameDBConfig,'user',"FROM_UNIXTIME(lastLoginTime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')");  //今日登陆数
        $todayorder = Db::name('v_annal_room')->where("FROM_UNIXTIME(endtime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')")->sum('roomcode'); //今日房卡消耗(大厅+俱乐部)
        $unsettleorder = Db::table('fa_v_annal_room')->field('roomid')->where("roomcode > 0 and FROM_UNIXTIME(endtime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')")->group('roomid,createtime')->count();//今日开房数(大厅+俱乐部)
        $sevendnu = Db::name('y_onlineorder')->where(['status'=>2])->where("FROM_UNIXTIME(addtime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')")->count();//今天订单量(客户端+代理)
        $sevendau = Db::name('y_onlineorder')->where(['status'=>2])->where("FROM_UNIXTIME(addtime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')")->sum('orderamount');//今天充值金额(客户端+代理)
        $todaywithdrawals = Db::name('y_withdrawals')->where("FROM_UNIXTIME(addtime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')")->sum('money');//今日代理提现申请金额
        $todayincome = Db::name('y_promotionincome')->where("FROM_UNIXTIME(addtime/1000,'%Y-%m-%d') = date_format(now(),'%Y-%m-%d')")->sum('money');//今日代理提成金额(代理支付提成+客户端支付提成)
        
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
		
		//获取游戏数据
        $this->view->assign([
            //总数据
            'countuser'        => $countuser,//总注册人数
            
            //当月数据
            'totaluser'         => $totaluser,//当月注册人数
            'totalviews'        => $totalviews,//当月开房数
            'totalorder'        => $totalorder,//当月消耗房卡
            'totalorderamount'  => $totalorderamount,//当月充值金额
            'totalagency'       => $totalagency,//当月充值金额
            'totalincome'       => $totalincome,//当月充值金额
            
            //今日数据
            'todayusersignup'  => $todayusersignup,//今日注册数
            'todayuserlogin'   => $todayuserlogin,//今日登陆数
            'todayorder'       => $todayorder,//今日房卡消耗
			'unsettleorder'    => $unsettleorder,//今日开房数
            'sevendnu'         => $sevendnu, //今日订单量
            'sevendau'         => $sevendau, //今日充值金额	
            'todaywithdrawals' => $todaywithdrawals,//今日代理提现申请金额
            'todayincome'      => $todayincome,//今日代理提成金额
			
        ]);

        return $this->view->fetch();
    }

}    
